<?php
require_once("sesion.php");
/*
$server = "50.63.108.127";
$username = "apptite";
$password = "M%m1234567890";
$database = "apptite";
*/

$server = "localhost";
$username = "root";
$password = "";
$database = "apptite";

$con = mysql_connect($server, $username, $password) or die ("No se conecto: " . mysql_error());

mysql_select_db($database, $con);

$usu = mysql_real_escape_string($_POST["usu"]);
$pass = mysql_real_escape_string($_POST["pass"]);

$clave = md5($pass);

$sql = "SELECT idRol,idusuario,indhabilitado,idsede FROM usuario WHERE nrodocumento='$usu' AND clave='$clave'";

if ($resultado = mysql_query($sql, $con)) {
    if (mysql_num_rows($resultado) > 0) {
        $fila = mysql_fetch_array($resultado);

        $sesion = new sesion();
        
        if ($fila[0] == 1 && $fila[2] == 1){
            $sesion->set("ses",$fila[0]);
            $sesion->set("usr",$fila[1]);
            $sesion->set("sed",$fila[3]);
            echo 'admin';
        }else if ($fila[0] == 2 && $fila[2] == 1){
            $sesion->set("ses",$fila[0]);
            $sesion->set("usr",$fila[1]);
            $sesion->set("sed",$fila[3]);
            echo 'cafeteria';
        }else if ($fila[0] == 3 && $fila[2] == 1){
            $sesion->set("ses",$fila[0]);
            $sesion->set("usr",$fila[1]);
            $sesion->set("sed",$fila[3]);
            echo 'estudiante';
        }else{
            echo 'inhabilitado';
        }        
    }
} else {
    echo false;
}
mysql_close($con);

?>